<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>libdill</title>
  <link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>

<h1>libdill: Structured Concurrency for C</h1>

<ul id='toplist'>
<li><a href="index.html">Home</a></li>
<li><a href="download.html">Download</a></li>
<li><a href="documentation.html">Documentation</a></li>
<li><a href="tutorial.html">Tutorials</a></li>
<li><a href="faq.html">FAQ</a></li>
</ul>
<h1 id="name">NAME</h1>
<p>ws_response_key - generates a WebSocket response key for a given request key</p>
<h1 id="synopsis">SYNOPSIS</h1>
<div class="sourceCode"><pre class="sourceCode c"><code class="sourceCode c"><span class="pp">#include </span><span class="im">&lt;libdill.h&gt;</span>

<span class="dt">int</span> ws_response_key(
    <span class="dt">const</span> <span class="dt">char</span>* request_key,
    <span class="dt">char</span>* response_key);</code></pre></div>
<h1 id="description">DESCRIPTION</h1>
<p><strong>WARNING: This is experimental functionality and the API may change in the future.</strong></p>
<p>WebSocket is a message-based protocol defined in RFC 6455. It can be used as a bidirectional communication channel for communication with a web server.</p>
<p>This is a helper function that can be used when doing a custom HTTP handshake for the WebSocket protocol (see <strong>WS_NOHTTP</strong> flag). On the server, it can be used to generates an RFC-compliant response key, to be filled into <strong>Sec-WebSocket-Accept</strong> field, for a request key received from the client. On the client side, it can be used to verify that the response key received from the server is correct.</p>
<p>The generated key is null-terminated.</p>
<p><strong>request_key</strong>: The request key, as passed in <strong>Sec-WebSocket-Key</strong> field.</p>
<p><strong>response_key</strong>: Buffer to hold the generated response key. It must be at least <strong>WS_KEY_SIZE</strong> bytes long.</p>
<p>This function is not available if libdill is compiled with <strong>--disable-sockets</strong> option.</p>
<h1 id="return-value">RETURN VALUE</h1>
<p>In case of success the function returns 0. In case of error it returns -1 and sets <strong>errno</strong> to one of the values below.</p>
<h1 id="errors">ERRORS</h1>
<ul>
<li><strong>EINVAL</strong>: Invalid argument.</li>
<li><strong>EPROTO</strong>: Supplied request key is not RFC 6455 compliant.</li>
</ul>
<h1 id="example">EXAMPLE</h1>
<div class="sourceCode"><pre class="sourceCode c"><code class="sourceCode c"><span class="dt">char</span> name[<span class="dv">256</span>];
<span class="dt">char</span> value[<span class="dv">256</span>];
http_recvfield(s, name, <span class="kw">sizeof</span>(name), value, <span class="kw">sizeof</span>(value), <span class="dv">-1</span>);
assert(strcasecmp(name, <span class="st">&quot;Sec-WebSocket-Key&quot;</span>) == <span class="dv">0</span>);
ws_response_key(value, response_key);
http_sendfield(s, <span class="st">&quot;Sec-WebSocket-Accept&quot;</span>, response_key, <span class="dv">-1</span>);</code></pre></div>
<h1 id="see-also">SEE ALSO</h1>
<p><strong>mrecv</strong>(3) <strong>mrecvl</strong>(3) <strong>msend</strong>(3) <strong>msendl</strong>(3) <strong>ws_attach_client</strong>(3) <strong>ws_attach_client_mem</strong>(3) <strong>ws_attach_server</strong>(3) <strong>ws_attach_server_mem</strong>(3) <strong>ws_detach</strong>(3) <strong>ws_done</strong>(3) <strong>ws_recv</strong>(3) <strong>ws_recvl</strong>(3) <strong>ws_request_key</strong>(3) <strong>ws_send</strong>(3) <strong>ws_sendl</strong>(3) <strong>ws_status</strong>(3)</p>
</body>
